﻿using Catel.Data;
using Catel.MVVM;

namespace Catel.Articles._03___MVVM.Examples.NestedUserControls
{
    /// <summary>
    /// Chair view model.
    /// </summary>
    public class ChairViewModel : ViewModelBase
    {
        #region Constructor & destructor
        /// <summary>
        /// Initializes a new instance of the <see cref="ChairViewModel"/> class.
        /// </summary>
        /// <param name="chair">The chair.</param>
        public ChairViewModel(Models.Chair chair)
        {
            // Store values
            Chair = chair;
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets the title of the view model.
        /// </summary>
        /// <value>The title.</value>
        public override string Title { get { return "Chair"; } }

        #region Models
        /// <summary>
        /// Gets or sets the chair.
        /// </summary>
        [Model]
        public Models.Chair Chair
        {
            get { return GetValue<Models.Chair>(ChairProperty); }
            private set { SetValue(ChairProperty, value); }
        }

        /// <summary>
        /// Register the Chair property so it is known in the class.
        /// </summary>
        public static readonly PropertyData ChairProperty = RegisterProperty("Chair", typeof(Models.Chair));
        #endregion

        #region View model
        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        [ViewModelToModel("Chair")]
        public string Name
        {
            get { return GetValue<string>(NameProperty); }
            set { SetValue(NameProperty, value); }
        }

        /// <summary>
        /// Register the Name property so it is known in the class.
        /// </summary>
        public static readonly PropertyData NameProperty = RegisterProperty("Name", typeof(string));
        #endregion
        #endregion
    }
}
